var claxlite = (function( window, undefined ) {
    var _claxlite;
    
    _claxlite = function( parent, struct ) {
        var clax, cache = {}, filter;
        
        if( !parent.prototype )
            parent = _claxlite( _claxlite.Native.__construct__, parent );
        
        if( !struct ) struct = new Object();
        
        clax = function() { if( this.init instanceof Function ) return this.init.apply( this, arguments ) };
        
        clax.prototype = clone( parent.prototype );
        
        filter = function( name ) {
            return !( name in _claxlite.Native )
        };
        
        if( cache == extend( clax.prototype, struct, filter, cache ) ) {
            extend( clax.prototype, { '$': function( fn ) {
                if( !(fn in cache ) ) return undefined;
                if( !isFunction( cache[fn] ) ) return cache[fn];
                return this.proxy( cache[fn] )
            }})
        }
         
       return clax
    };
    
    _claxlite.Native = _claxlite.prototype = {
        '__construct__': function() {},
        
        "proxy": function( fn ) {
            var args;
            
            args = slice.call( arguments, 0 );
            
            if( isFunction( fn ) ) {
                args.unshift( this );         
                return bind.apply( window, args )
            }
            
            return null
		},
		
        "aspect": function( name, fn, once ) {
            this[name] = this.proxy( function( ori ) {
                var args = slice.call( arguments, 1 );
                if( once ) this[name] = ori;
                return fn.apply( this, args );
            }, this[name] )
        }
    };
    
    _claxlite.Native.__construct__.prototype = _claxlite.prototype;
    
    var array = [], object = {}, noop = function() {};
    var slice = array.slice, toString = object.toString;
    var clone = function( o ) {
        var ret = new Function();
        
        ret.prototype = o;
        return new ret()
    },
    
    bind = function( obj, fn ) {
        var method, args;

        args = slice.call( arguments, 2 );
        method = isFunction( fn )?fn:noop;

        return function() {
	        var conargs;

	        conargs = slice.call( arguments, 0 );
	        conargs = args.concat( conargs );

	        return method.apply( obj, conargs )
        }
    },
    
    extend = function( inObj, obj, cacheFilter, cache ) {
        var _cache={}, is;
        
        cache = cache || {};
        for( var key in obj ) {
            if( cacheFilter && !cacheFilter( key ) ) continue;
            if( key in inObj ) cache[ is=key ] = inObj[ key ];
            inObj[ key ] = obj[ key ];
        }
        
        return (is===undefined)?_cache:cache
    },
    
    isFunction = function( f ) {
        return toString.call( f ) === '[object Function]'
    };
    
    extend( _claxlite, {
        'clone': clone,
        'bind': bind,
        'extend': extend,
        'isFunction': isFunction
    });
    
    window._claxlite = _claxlite;
    return _claxlite
})( this );
